package com.express.aop;


import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class AspectTest {

    private static Logger logger = LoggerFactory.getLogger(AspectTest.class);

    @Pointcut("@annotation(Token)")
    public void interfaceAspect() {
        logger.info("interface开始aop切点");
    }

    @Around("interfaceAspect()")
    public Object around(ProceedingJoinPoint point) {
        logger.info("进入aop 拦截方法");
        return null;
    }
    @Before("interfaceAspect()")
    public void doBefore(JoinPoint joinPoint) {
        System.out.println(" is before ");
    }

    @After("interfaceAspect()")
    public void after(JoinPoint joinPoint) {
        System.out.println(" is after ");
    }

    /**
     * 获取请求的参数，结果
     *
     * @param joinPoint
     * @param result
     */
    @AfterReturning(pointcut = "interfaceAspect()", returning = "result")
    public void afterReturnExcute(JoinPoint joinPoint, Object result) {
        System.out.println(" is after ");
    }

    /**
     * 异常通知 用于拦截记录异常日志
     *
     * @param joinPoint
     * @param ex
     */
    @AfterThrowing(pointcut = "interfaceAspect()", throwing = "ex")
    public void AfterThrowing(JoinPoint joinPoint, Throwable ex) {

    }
}
